<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.List,com.dao.Message,java.util.List,com.dao.Users"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="pg" uri="http://jsptags.com/tags/navigation/pager"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>留言板</title>
</head>
<body>
	<p align="right" style="width:700">当前应用中一共有${onlineUserNum}人在线;其中有${loginUserNum}人登录</p>
	<div style="width:600px; position:relative; left:150px;">
	<h1 align="center">留言板</h1>
	<c:set var="submittype" value="${sessionScope.MessageType}"/>
	<c:forEach items="${page.data}" var="obj">
	<table width="600" border="1" >
		<tr>
			<td>ID:</td>
			<td>${obj.id}</td>
		</tr>
		<tr>
			<td>账号：</td>
			<td>${obj.musername}</td>
		</tr>
		<tr>
			<td>昵称：</td>
			<td>${obj.author}</td>
		</tr>
		<tr>
			<td>主题：</td>
			<td>${obj.title}</td>
		</tr>
		<tr>
			<td>内容：</td>
			<td>${obj.content}</td>
		</tr>
		<tr>
			<td>日期：</td>
			<td>${obj.date}</td>
		</tr>
		<c:if test="${submittype!='youke'||submittype=='benren'||submittype=='zhiding'}">
			<c:set var="u" value="${sessionScope.UserMessage}"/>
			<c:if test="${u.username==obj.musername||u.man_id==1}">
			<tr>
				<td><a href="${pageContext.request.contextPath}/message/updateMessage.jsp?title=${obj.title}&content=${obj.content}&id=${obj.id}">修改留言</a></td>
				<td><a href="${pageContext.request.contextPath}/MessageServlet?submittype=delete&Musername=${obj.musername}&id=${obj.id}">删除留言</a></td>
			</tr>
			</c:if>
		</c:if>
	</table>
	</c:forEach>
	<pg:pager url="${pageContext.request.contextPath}/MessageServlet"	items="${page.maxRows}"	maxPageItems="${page.pageSize}"  maxIndexPages="5">
		<pg:index>
			<pg:first unless="current">
				<a href="${pageUrl}&pageNumber=${pageNumber}">首页</a>
			</pg:first>
			<pg:prev>
				<a href="${pageUrl}&pageNumber=${pageNumber}">上一页(${pageNumber})</a>
			</pg:prev>
			<pg:pages>
				<a href="${pageUrl}&pageNumber=${pageNumber}">${pageNumber}</a>				
			</pg:pages>
			<pg:next>
				<a href="${pageUrl}&pageNumber=${pageNumber}">下一页(${pageNumber})</a>
			</pg:next>
			<pg:last unless="current">
				<a href="${pageUrl}&pageNumber=${pageNumber}">尾页</a>
			</pg:last>
		</pg:index>
	</pg:pager>
	</div>
	<div style="width:300px; position:absolute; top:100px; left:850px; text-align:center; line-height:30px;">
	<c:choose>
	<c:when test="${submittype=='youke'}">
		<form action="${pageContext.request.contextPath}/UsersServlet" method="post">
				<input name="submittype" type="submit" value="退出"/>
	  	</form>
	  	<form action="${pageContext.request.contextPath}/users/add.jsp" method="post">
				<input name="submittype" type="submit" value="注册"/>
	  	</form>
	</c:when>
	<c:when test="${submittype=='benren' ||submittype=='zhiding'}">
		<form action="${pageContext.request.contextPath}/MessageServlet" method="post">
				<input name="submittype" type="submit" value="返回查看所有留言"/>
	  	</form>
	</c:when>
	<c:otherwise>
		<form action="${pageContext.request.contextPath}/users/control.jsp" method="post">
				<input name="submittype" type="submit" value="用户管理"/>
	  	</form>
		<form action="message/addMessage.jsp" method="post">
				<input name="submittype" type="submit" value="添加留言"/>
	  	</form>
		<form action="${pageContext.request.contextPath}/MessageServlet" method="post">
				<input name="submittype" type="submit" value="查询本人留言"/>
	  	</form>
	 	<form action="${pageContext.request.contextPath}/MessageServlet" method="post">
			查询指定用户留言：<input name="name" type="text" value="">
			<input name="submittype" type="submit" value="查询指定用户留言"/><br>
		</form>
		<form action="${pageContext.request.contextPath}/UsersServlet" method="post">
			<input type="submit" name="submittype" value="退出登录">
		</form>
	</c:otherwise>
	</c:choose>
	<p>${error}</p>
	</div>
</body>
</html>